package com.ruoyi.web.controller.university;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.university.domain.University;
import com.ruoyi.university.service.IUniversityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 高校管理Controller
 * 
 * @author atzxc
 * @date 2024-04-14
 */
@RestController
@RequestMapping("/university/university")
public class UniversityController extends BaseController
{
    @Autowired
    private IUniversityService universityService;

    /**
     * 查询高校管理列表
     */
    @PreAuthorize("@ss.hasPermi('university:university:list')")
    @GetMapping("/list")
    public TableDataInfo list(University university)
    {
        startPage();
        List<University> list = universityService.selectUniversityList(university);
        return getDataTable(list);
    }

    /**
     * 导出高校管理列表
     */
    @PreAuthorize("@ss.hasPermi('university:university:export')")
    @Log(title = "高校管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, University university)
    {
        List<University> list = universityService.selectUniversityList(university);
        ExcelUtil<University> util = new ExcelUtil<University>(University.class);
        util.exportExcel(response, list, "高校管理数据");
    }

    /**
     * 获取高校管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('university:university:query')")
    @GetMapping(value = "/{universityId}")
    public AjaxResult getInfo(@PathVariable("universityId") Long universityId)
    {
        return success(universityService.selectUniversityByUniversityId(universityId));
    }

    /**
     * 新增高校管理
     */
    @PreAuthorize("@ss.hasPermi('university:university:add')")
    @Log(title = "高校管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody University university)
    {
        return toAjax(universityService.insertUniversity(university));
    }

    /**
     * 修改高校管理
     */
    @PreAuthorize("@ss.hasPermi('university:university:edit')")
    @Log(title = "高校管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody University university)
    {
        return toAjax(universityService.updateUniversity(university));
    }

    /**
     * 删除高校管理
     */
    @PreAuthorize("@ss.hasPermi('university:university:remove')")
    @Log(title = "高校管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{universityIds}")
    public AjaxResult remove(@PathVariable Long[] universityIds)
    {
        return toAjax(universityService.deleteUniversityByUniversityIds(universityIds));
    }
}
